package com.zc.finkDemo.config;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class DruidConnectionPool {
    private static DruidConnectionPool instance;
    private DruidDataSource dataSource;
    private DruidConnectionPool() {
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/database");
        dataSource.setUsername("username");
        dataSource.setPassword("password");
        dataSource.setInitialSize(5); // 设置初始连接池大小
        // 可以设置更多连接池参数，如最大连接数、最小空闲连接数等
    }
    public static synchronized DruidConnectionPool getInstance() {
        if (instance == null) {
            instance = new DruidConnectionPool();
        }
        return instance;
    }
    public synchronized Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
}